<template>
    <view class="contentBack0">
        <view class="divc tops">
            <u-image width="608rpx" height="196rpx" :src="$config.LoginLogo"></u-image>
        </view>
        <view class="content">
            <u-form class="loginForm" :model="thisData" ref="loginFormRef" :rules="rules" label-width="85" labelPosition="left">
                <u-form-item label="用户代码" prop="loginCode" borderBottom>
                    <u-input v-model="thisData.loginCode" placeholder="请输入用户代码" border="none" />
                </u-form-item>
                <u-form-item label="姓名" prop="loginName" borderBottom>
                    <u-input v-model="thisData.loginName" placeholder="请输入账户" border="none" />
                </u-form-item>
                <u-form-item label="密码" prop="password" borderBottom>
                    <u-input v-model="thisData.password" type="password" placeholder="请输入密码" border="none" v-show="pswFlag" />
                    <u-input v-model="thisData.password" type="text" placeholder="请输入密码" border="none" v-show="!pswFlag" />
                    <u-icon :name="pswFlag ? 'eye-off' : 'eye'" color="#999" size="20" @click="pswFlag = !pswFlag"></u-icon>
                </u-form-item>
            </u-form>
            <u-button class="mart-60" type="primary" @click="login">登录</u-button>
            <view class="textc mart-30 fz-28">版本号：{{ $config.Version }}</view>
        </view>
    </view>
</template>

<script>
export default {
    data() {
        return {
            pswFlag: true,
            thisData: {
                loginCode: "",
                loginName: this.$config.Username,
                password: this.$config.Password,
            },
            rules: {
                loginName: [{ required: true, message: "请输入姓名", trigger: ["change", "blur"] }],
                password: [{ required: true, message: "请输入密码", trigger: ["change", "blur"] }],
            },
        };
    },
    methods: {
        login() {
            this.$refs.loginFormRef
                .validate()
                .then(() => {
                    uni.showLoading();
                    this.$app.Login(this.thisData, {
                        success: (res) => {
                            if (res.code == 0) {
                                uni.setStorageSync(this.$config.TokenKey, res.data);

                                if (this.$config.UploadPosition == this.$enums.UploadPosition.远程) {
                                    this.$app.GetQiniuToken();
                                }

                                this.$app.UpdateMe({
                                    success: (res) => {
                                        getApp().globalData = res;
                                        uni.setStorageSync(this.$config.MeKey, res);
                                        uni.reLaunch({ url: "/pages/workbench/workbench" });
                                    },
                                });
                            } else {
                                this.$app.Tips({ title: res.msg, icon: "none" });
                            }
                        },
                    });
                })
                .catch(() => {});
        },
    },
};
</script>

<style scoped>
.tops {
    padding-top: 35%;
    margin-bottom: 100rpx;
}
</style>
